// 
// File:   main.cc
// Author: ben
//
// Created on October 11, 2008, 3:18 PM
//
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>

#include "graphcreator.h"


IplImage*	g_image = NULL;
IplImage*	g_gray = NULL;
int		g_thresh = 100;
CvMemStorage* 	g_storage = NULL;

void on_trackbar(int){
	if( g_storage == NULL ){
		g_gray = cvCreateImage( cvGetSize( g_image ), 8, 1 );
		g_storage = cvCreateMemStorage(0);
	} else {
		cvClearMemStorage( g_storage );
	}

	CvSeq* contours = 0;
	cvCvtColor( g_image, g_gray, CV_BGR2GRAY );
	cvThreshold( g_gray, g_gray, g_thresh, 255, CV_THRESH_BINARY );
	cvFindContours( g_gray, g_storage, &contours );
	cvZero( g_gray );
	if( contours ){
		cvDrawContours(
			g_gray,
			contours,
			cvScalarAll(255),
			cvScalarAll(255),
			100 );
	}
	cvShowImage( "Contours", g_gray );
}


int main(int argc, char** argv)
{

	g_image = cvLoadImage( "pub_irish.jpg" );
	cvNamedWindow( "Contours", 1 );
	cvCreateTrackbar( "Threshold", "Contours", &g_thresh, 255, on_trackbar );
	on_trackbar(0);
	cvWaitKey();

	return 0;
}
/*

int main(int argc, char** argv) {

    cout << "====================================" << endl;
    cout << "http://code.google.com/p/imagegraph/" << endl;
    cout << "     Benoit.Vermoortel@gmail.com" << endl;
    cout << "====================================" << endl;


    
    if(argc!=3){
        cout << "CALC [foldername] [XMLFILE]" << endl << endl;
        cout << "example: calc data filelist.xml" << endl;
        cout << "if the XML file 'filelist.xml' is in the 'data' folder" << endl;
        
    }
    else{
        cout << "FOLDER:\t\t" << argv[1] << endl;
        cout << "XML FILE:\t" << argv[2] << endl;
        AnalyseInXML(argv[1], argv[2]);
        cout << "Done!" << endl;
    }

        

        return (EXIT_SUCCESS);
}
*/

//
// 
//
